import time
from timeit import timeit

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome(executable_path='Chromedriver.exe')
driver.get("http://www.baidu.com")

# 需求：使用cookie实现跳过登录
# 1). 手动登录百度，获取cookie
# 2). 使用获取到的cookie，达到登录目的，然后就可以执行登录之后的操作


# 1). 手动登录百度，获取cookie
# 1. 登录baidu，登录成功后抓取 (BDUSS)
# 2. 使用add_cookie()方法，添加 (BDUSS)键和值
driver.add_cookie({"name":"BDUSS", "value":"ZhRHFQU1p-amJHODhpaXlNRU84aER3YU9LQ20wLXREWTdKaXJJa3AxaH5uaTlwSUFBQUFBJCQAAAAAAAAAAAEAAAA41X-swfprb8Ckd2luZHkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH8RCGl~EQhpcG"})


cookies = driver.get_cookies()
print("cookies内容为:",cookies)
for co in cookies:
    print(co['name'])

# 3. 调用刷新方法 driver.refresh()
driver.refresh()